import {urlToBufferXor} from "@/utils/imagedec";

export default {
  install(app){

    app.directive('image-decrypt', (el, binding) => {
      const img = binding.value;
      if(img!=null &&img!=""){
        if (img.includes('.p.webp')) {
          urlToBufferXor(img).then(dataurl => {
            try {
              el.src = dataurl;
              el.setAttribute('src', dataurl);
            } catch (e) {
              console.log('Cannot redefine property: src');
            }
          });
        } else {
          el.src = img;
          el.setAttribute('preview', img);
        }
      }else{

          el.src = img;
          el.setAttribute('preview', img);

      }

    })
  }
}
